package com.ruoyi.znjc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.znjc.domain.ZnjcRules;
import com.ruoyi.znjc.service.IZnjcRulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农业规则Controller
 * 
 * @author ZNJC
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/znjc/rules")
public class ZnjcRulesController extends BaseController
{
    @Autowired
    private IZnjcRulesService znjcRulesService;

    /**
     * 查询农业规则列表
     */
    @PreAuthorize("@ss.hasPermi('znjc:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZnjcRules znjcRules)
    {
        startPage();
        List<ZnjcRules> list = znjcRulesService.selectZnjcRulesList(znjcRules);
        return getDataTable(list);
    }

    /**
     * 导出农业规则列表
     */
    @PreAuthorize("@ss.hasPermi('znjc:rules:export')")
    @Log(title = "农业规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZnjcRules znjcRules)
    {
        List<ZnjcRules> list = znjcRulesService.selectZnjcRulesList(znjcRules);
        ExcelUtil<ZnjcRules> util = new ExcelUtil<ZnjcRules>(ZnjcRules.class);
        util.exportExcel(response, list, "农业规则数据");
    }

    /**
     * 获取农业规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('znjc:rules:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(znjcRulesService.selectZnjcRulesByRuleId(ruleId));
    }

    /**
     * 新增农业规则
     */
    @PreAuthorize("@ss.hasPermi('znjc:rules:add')")
    @Log(title = "农业规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZnjcRules znjcRules)
    {
        return toAjax(znjcRulesService.insertZnjcRules(znjcRules));
    }

    /**
     * 修改农业规则
     */
    @PreAuthorize("@ss.hasPermi('znjc:rules:edit')")
    @Log(title = "农业规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZnjcRules znjcRules)
    {
        return toAjax(znjcRulesService.updateZnjcRules(znjcRules));
    }

    /**
     * 删除农业规则
     */
    @PreAuthorize("@ss.hasPermi('znjc:rules:remove')")
    @Log(title = "农业规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(znjcRulesService.deleteZnjcRulesByRuleIds(ruleIds));
    }
}
